﻿using BrightIdeasSoftware;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BO;
using System.Collections;
using UI.Core;
using System.Data.SqlClient;
namespace UI
{
    public partial class TableReport : ReportFormBase
        //,IMenuForm
    {
        public TableReport()
        {
            InitializeComponent();
        }

        protected override void InitGrid()
        {
           
        }
        IEnumerable mySource;

        protected override IEnumerable MySource
        {
            get
            {
                return mySource;
            }
        }
        protected override void FetchData()
        {
            var timeNow=DateTime.Now;
          //需要改.
          var  sqlTxt = string.Format(
@"
Select 
Billing.*,
Company.*,
Center.*,
Department.*,
Staff.*,
ProductGroup.*,
Product.*
From Billing 
Left join Company On Billing.CompanyName=Company.Name
Left join Center On Billing.CenterName=Center.Name
Left join Department On Billing.DepartmentName=Department.Name
Left join Staff on Billing.StaffName=Staff.Name
Left join ProductGroup on Billing.ProductGroupName=ProductGroup.Name
Left join Product on Billing.ProductName=Product.Name
", timeNow.Year);
            var dt = BinDataTableAdapter.GetDataTable( CommandType.Text,sqlTxt);
       Invoke(new Action(()=>{
           MyGrid.Columns.Clear();
            foreach(DataColumn col in dt.Columns)
            {
                MyGrid.Columns.Add(col.ColumnName);
            }
       }
            ));
            mySource =dt.DefaultView;
        
        }
    }
}
